package com.wuxi.zhang.java8;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author zhang on 2019/7/17.
 */
public class Java8Tester {

    public static void main(String[] args) {
        List<String> names1 = new ArrayList<>();
        names1.add("zhang");
        names1.add("wang");
        names1.add("xiao");

        List<String> names2 = new ArrayList<>();
        names2.add("zhang");
        names2.add("wang");
        names2.add("xiao");

        //测试排序倒叙 java7
        sortUsingJava7(names1);
        System.out.println("name1=" + names1);

        //测试排序倒叙 java8
        sortUsingJava8(names2);
        System.out.println("names2=" + names2);
    }

    /**
     * java7 倒叙
     *
     * @param names1
     */
    private static void sortUsingJava7(List<String> names1) {
        Collections.sort(names1, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o2.compareTo(o1);
            }
        });
    }

    /**
     * java8 倒叙
     *
     * @param names2
     */
    private static void sortUsingJava8(List<String> names2) {
        Collections.sort(names2, (o1, o2) -> o2.compareTo(o1));
    }


}
